import { createApp } from 'vue'
import { initPreferences } from '@/lib/preferences';
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { setupElementPlus } from 'epic-designer/dist/ui/elementPlus';
import App from './App.vue'
import config from './model/config';
import tool from './helper/tool';
import { overridesPreferences } from './preferences';
import { initStores } from './store/setup';
import { setupDesignerExtensions } from './designer-extensions';

// 引入element-plus样式
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
// 引入epic-designer样式
import 'epic-designer/dist/style.css';

import './assets/animation.css'
import './assets/app.css'
import './assets/theme.scss'
import './assets/index.css'

declare global {
  interface Window {
    global: any;
  }
}

if (typeof window !== 'undefined') {
  window.global = window;
}


const env = import.meta.env.PROD ? 'prod' : 'dev';
const appVersion = import.meta.env.VITE_APP_VERSION;
const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`;


// 执行扩展函数
setupDesignerExtensions();

const app = createApp(App);

app.config.globalProperties.$config = config;
app.config.globalProperties.$tool = tool;

app.use(ElementPlus, {
  locale: zhCn,
});

// app偏好设置初始化
await initPreferences({
  namespace,
  overrides: overridesPreferences,
});
await initStores(app, { namespace });

// 注册Element UI
setupElementPlus();

app.mount('#app');
